﻿using FarPoint.Win.Spread;
using FarPoint.Win.Spread.CellType;
using GrapeCity.CalcEngine;
using GrapeCity.Spreadsheet;
using Spread.Common.Features.Sample;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Spread.Worksheet.Features
{
    public partial class TextToColumn : BaseSampleControl
    {
        public TextToColumn()
        {
            InitializeComponent();

            using (var stream = new MemoryStream(Properties.Resources.CustomerData))
            {
                _fpSpread.OpenExcel(stream);
            }
            _fpSpread.AsWorkbook().ActiveSheet.Cells[0, 0, 39, 0].Select();
        }

        private void OnTextToColumnMenuItemClick(object sender, EventArgs e)
        {
             var textToColumnDialog = FarPoint.Win.Spread.Dialogs.BuiltInDialogs.TextToColumns(_fpSpread);

            if (textToColumnDialog != null)
                textToColumnDialog.Show(_fpSpread);
        }

        private void OnTextToColumnByCodeClick(object sender, EventArgs e)
        {
            var sheet = _fpSpread.AsWorkbook().ActiveSheet;
            var selection = sheet.Selection;

            sheet.Cells[selection.Row, selection.Column, selection.Row2, selection.Column2]
                .TextToColumns("$B$1", TextParsingType.Delimited, TextQualifier.DoubleQuote, false, false, false, true);
        }
    }
}

//
// TextToColumn.Designer.cs
//

namespace Spread.Worksheet.Features
{
    partial class TextToColumn
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
           this._fpSpread = new FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None);
            this._fpSpread_Sheet1 = new FarPoint.Win.Spread.SheetView();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.textToColumnToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this._textToColumnCodeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.pnlMain.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this._fpSpread)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this._fpSpread_Sheet1)).BeginInit();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // pnlMain
            // 
            this.pnlMain.Controls.Add(this._fpSpread);
            this.pnlMain.Controls.Add(this.menuStrip1);
            this.pnlMain.Margin = new System.Windows.Forms.Padding(5, 5, 5, 5);
            this.pnlMain.Size = new System.Drawing.Size(1071, 1030);
            // 
            // pnlControls
            // 
            this.pnlControls.Margin = new System.Windows.Forms.Padding(5, 5, 5, 5);
            this.pnlControls.Size = new System.Drawing.Size(355, 1030);
            // 
            // _fpSpread
            // 
            this._fpSpread.AccessibleDescription = "";
            this._fpSpread.Dock = System.Windows.Forms.DockStyle.Fill;
            this._fpSpread.Location = new System.Drawing.Point(0, 28);
            this._fpSpread.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this._fpSpread.Name = "_fpSpread";
            this._fpSpread.Sheets.AddRange(new FarPoint.Win.Spread.SheetView[] {
            this._fpSpread_Sheet1});
            this._fpSpread.Size = new System.Drawing.Size(1071, 1002);
            this._fpSpread.TabIndex = 1;
            // 
            // _fpSpread_Sheet1
            // 
            this._fpSpread_Sheet1.Reset();
            this._fpSpread_Sheet1.SheetName = "Sheet1";
            // Formulas and custom names must be loaded with R1C1 reference style
            this._fpSpread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1;
            this._fpSpread_Sheet1.ColumnFooter.DefaultStyle.BackColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.ColumnFooter.DefaultStyle.ForeColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.ColumnFooter.DefaultStyle.Locked = false;
            this._fpSpread_Sheet1.ColumnFooterSheetCornerStyle.BackColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.ColumnFooterSheetCornerStyle.ForeColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.ColumnFooterSheetCornerStyle.Locked = false;
            this._fpSpread_Sheet1.ColumnHeader.DefaultStyle.BackColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.ColumnHeader.DefaultStyle.ForeColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.ColumnHeader.DefaultStyle.Locked = false;
            this._fpSpread_Sheet1.DefaultStyle.BackColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.DefaultStyle.ForeColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.DefaultStyle.Locked = false;
            this._fpSpread_Sheet1.FilterBar.DefaultStyle.BackColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.FilterBar.DefaultStyle.ForeColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.FilterBar.DefaultStyle.Locked = false;
            this._fpSpread_Sheet1.FilterBarHeaderStyle.BackColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.FilterBarHeaderStyle.ForeColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.FilterBarHeaderStyle.Locked = false;
            this._fpSpread_Sheet1.RowHeader.DefaultStyle.BackColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.RowHeader.DefaultStyle.ForeColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.RowHeader.DefaultStyle.Locked = false;
            this._fpSpread_Sheet1.SheetCornerStyle.BackColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.SheetCornerStyle.ForeColor = System.Drawing.Color.Empty;
            this._fpSpread_Sheet1.SheetCornerStyle.Locked = false;
            this._fpSpread_Sheet1.SheetCornerStyle.VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Center;
            this._fpSpread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1;
            // 
            // menuStrip1
            // 
            this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.textToColumnToolStripMenuItem,
            this._textToColumnCodeToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(1071, 28);
            this.menuStrip1.TabIndex = 2;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // textToColumnToolStripMenuItem
            // 
            this.textToColumnToolStripMenuItem.Name = "textToColumnToolStripMenuItem";
            this.textToColumnToolStripMenuItem.Size = new System.Drawing.Size(134, 24);
            this.textToColumnToolStripMenuItem.Text = "Text To Column...";
            this.textToColumnToolStripMenuItem.Click += new System.EventHandler(this.OnTextToColumnMenuItemClick);
            // 
            // _textToColumnCodeToolStripMenuItem
            // 
            this._textToColumnCodeToolStripMenuItem.Name = "_textToColumnCodeToolStripMenuItem";
            this._textToColumnCodeToolStripMenuItem.Size = new System.Drawing.Size(209, 24);
            this._textToColumnCodeToolStripMenuItem.Text = "Text To Column (With Code)";
            this._textToColumnCodeToolStripMenuItem.Click += new System.EventHandler(this.OnTextToColumnByCodeClick);
            // 
            // TextToColumn
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Margin = new System.Windows.Forms.Padding(5, 5, 5, 5);
            this.Name = "TextToColumn";
            this.Size = new System.Drawing.Size(1427, 1030);
            this.pnlMain.ResumeLayout(false);
            this.pnlMain.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this._fpSpread)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this._fpSpread_Sheet1)).EndInit();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private FarPoint.Win.Spread.FpSpread _fpSpread;
        private FarPoint.Win.Spread.SheetView _fpSpread_Sheet1;
        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem textToColumnToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem _textToColumnCodeToolStripMenuItem;
    }
}
